<?php
function reserveItems($array, $user_id){
	if(is_array($array)){
		$query1 = "INSERT INTO borrow (item_id, qty, user_id, from_date, to_date, borrow_date, tracking, requiring_subject, pickup_time, start_time) VALUES ";
		$value1 = '';
		$query2 = "UPDATE item SET item_status = 'BORROWED' WHERE item_id IN ";
		$ids = '';
		$tracking = genereateTracking();
		$table = '<h4>Tracking Code: '.$tracking.'</h4><table width="95%" border="0" cellpadding="1" cellspacing="1">
				<thead>
					<tr>
						<th>QTY</th>
						<th>Name</th>
						<th>Requiring Subject</th>
						<th>Date</th>
						<th>Pickup Time</th>
						
					</tr>
				</thead>
				<tbody>';
		foreach($array as $item){
		$value1 = $value1."('".$item['id']."', '".$item['qty']."', '$user_id', '".$item['from']."', '".$item['to']."', '".NOW."', '".$tracking."', '".$item['subject']."', '".$item['time_start']."', '".$item['time']."' ), ";
		$ids = $ids.$item['id'].',';
		$table = $table.'<tr><td>'.$item['qty'].'</td><td>'.$item['name'].'</td><td>'.$item['subject'].'</td><td>'.$item['from'].' to '.$item['to'].'</td><td>'.$item['time_start'].'</td></tr>'.$item['time'].'';
		}
		$value1 = substr_replace($value1, '', -2);
		$ids = substr_replace($ids, '', -1);
		
		$query1=$query1.$value1;
		$query2=$query2.'('.$ids.')';
		
		
		mysql_query($query1) or die('Error: '.$query1.'<br/><br/>'.mysql_error());
		mysql_query($query2) or die('Error: '.mysql_error());
		$table = $table.'</tbody></table>';
		
		$_SESSION['reserved_items'] = $table;
		
	}	
}
?>